package cn.iocoder.yudao.module.member.service.studentEducationalExperience;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.member.controller.admin.studentEducationalExperience.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.studentEducationalExperience.StudentEducationalExperienceDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.member.convert.studentEducationalExperience.StudentEducationalExperienceConvert;
import cn.iocoder.yudao.module.member.dal.mysql.studentEducationalExperience.StudentEducationalExperienceMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;

/**
 * 用户简历教育经历 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class StudentEducationalExperienceServiceImpl implements StudentEducationalExperienceService {

    @Resource
    private StudentEducationalExperienceMapper studentEducationalExperienceMapper;

    @Override
    public Long createStudentEducationalExperience(StudentEducationalExperienceCreateReqVO createReqVO) {
        // 插入
        StudentEducationalExperienceDO studentEducationalExperience = StudentEducationalExperienceConvert.INSTANCE.convert(createReqVO);
        studentEducationalExperienceMapper.insert(studentEducationalExperience);
        // 返回
        return studentEducationalExperience.getId();
    }

    @Override
    public void updateStudentEducationalExperience(StudentEducationalExperienceUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateStudentEducationalExperienceExists(updateReqVO.getId());
        // 更新
        StudentEducationalExperienceDO updateObj = StudentEducationalExperienceConvert.INSTANCE.convert(updateReqVO);
        studentEducationalExperienceMapper.updateById(updateObj);
    }

    @Override
    public void deleteStudentEducationalExperience(Long id) {
        // 校验存在
        this.validateStudentEducationalExperienceExists(id);
        // 删除
        studentEducationalExperienceMapper.deleteById(id);
    }

    private void validateStudentEducationalExperienceExists(Long id) {
        if (studentEducationalExperienceMapper.selectById(id) == null) {
            throw exception(STUDENT_EDUCATIONAL_EXPERIENCE_NOT_EXISTS);
        }
    }

    @Override
    public StudentEducationalExperienceDO getStudentEducationalExperience(Long id) {
        return studentEducationalExperienceMapper.selectById(id);
    }

    @Override
    public List<StudentEducationalExperienceDO> getStudentEducationalExperienceList(Collection<Long> ids) {
        return studentEducationalExperienceMapper.selectBatchIds(ids);
    }

    @Override
    public List<StudentEducationalExperienceDO> getStudentEducationalExperienceByStudentId(Long id) {
        return studentEducationalExperienceMapper.selectListByStudentId(id);
    }

    @Override
    public PageResult<StudentEducationalExperienceDO> getStudentEducationalExperiencePage(StudentEducationalExperiencePageReqVO pageReqVO) {
        return studentEducationalExperienceMapper.selectPage(pageReqVO);
    }

    @Override
    public List<StudentEducationalExperienceDO> getStudentEducationalExperienceList(StudentEducationalExperienceExportReqVO exportReqVO) {
        return studentEducationalExperienceMapper.selectList(exportReqVO);
    }

}
